{% extends 'rbac/base.html' %}
{% block addcss %}
    <link href="/static/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
{% endblock %}
{% block content %}
    {% load menu %}
    {% breadcrumb request %}

    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>用户列表</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link" href="">
                                <i class="fa fa-chevron-up"></i>
                            </a>

                        </div>
                    </div>

                    <div class="ibox-content">
                        {% csrf_token %}
                        <p class="w">
                            {% if   request|has_permission:'rbac:user_add' %}
                                <a href="{% url 'rbac:user_add' %}" class="btn btn-w-m btn-primary">添加用户</a>
                            {% endif %}
                        </p>
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover text-center">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>用户名</th>
                                    <th>真实姓名</th>
                                    <th>邮件</th>
                                    <th>联系方式</th>
                                    <th>重置密码</th>
                                    {% if   request|has_permission:'rbac:user_del' and request|has_permission:'rbac:user_del' %}
                                        <th>操作</th>
                                    {% endif %}
                                </tr>
                                </thead>
                                <tbody>
                                {% for user in users %}
                                    <tr>
                                        <td>{{ forloop.counter }}</td>
                                        <td>{{ user.username|default:'Null' }}</td>
                                        <td>{{ user.fullname|default:'Null' }}</td>
                                        <td>{{ user.email|default:'Null' }}</td>
                                        <td>{{ user.phone|default:'Null' }}</td>
                                        <td>
                                            <button type="button" class=" btn btn-info btn-sm a-reset"
                                                    reset-id="{{ user.pk }}"
                                                    reset-url="/rbac/resetpasswd/{{ user.pk }}/"><i
                                                    class="fa fa-wrench"></i>重置
                                            </button>
                                        </td>
                                        {% if   request|has_permission:'rbac:user_del' and request|has_permission:'rbac:user_del' %}
                                            <td>
                                                {% if   request|has_permission:'rbac:user_del' %}
                                                    <a href="{% url 'rbac:user_edit' pk=user.id %}"
                                                       class=" btn btn-primary btn-sm get_user_info">
                                                        <i class="fa fa-edit"></i>修改
                                                    </a>
                                                {% endif %}
                                                {% if   request|has_permission:'rbac:user_del' %}
                                                    <a href="#" id="{{ user.id }}"
                                                       class=" btn btn-danger btn-sm a-del"
                                                       del-url="{% url 'rbac:user_del' pk=user.id %}">
                                                        <i class="fa fa-times"></i>删除
                                                    </a>
                                                {% endif %}
                                            </td>
                                        {% endif %}
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>
                        <div class="col-sm-12 clearfix">
                            <ul class="pagination float-right">
                                {{ pager.page_html|safe }}
                            </ul>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block addjs %}
    <script src="/static/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="/static/rbac/del.js"></script>
{% endblock %}
